home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 287_01 / blkclip.c < prev    next >
Text File  |  1989-05-23  |  2KB  |  52 lines

  1. #include <stdio.h>
  2. #include <gds.h>
  3.  
  4. #define ERROR (-1)
  5. #define OK 0
  6. #define VOIDBLOCK 1
  7.  
  8. /*==============================================================*
  9.  *  This file contains the following routine:                   *
  10.  *      blockclip       clip a block against the window         *
  11.  *                      this function is used by HorzLine,      *
  12.  *                      VertLine, BlockCopy                     *
  13.  *                                                              *
  14.  *==============================================================*/
  15.  
  16. blockclip(x,y,length,height)
  17. int *x, *y, *length, *height;
  18. {
  19.     /* return if the whole block is above or on the right of the window */
  20.     if (*y > WINY2 || *x > WINX2) {
  21.         return(VOIDBLOCK);
  22.     }
  23.     /* any part of the line on the top of the window  */
  24.     if (*y < WINY1)
  25.         /* yes */
  26.         if ((*height -= (WINY1 - *y)) <= 0) {
  27.             return(VOIDBLOCK); 
  28.         } else
  29.           *y=WINY1;
  30.  
  31.     /* any part of the line on the left of window ? */
  32.     if (*x < WINX1)
  33.         /* yes */
  34.         if ((*length -= (WINX1 - *x)) <= 0) {
  35.             return(VOIDBLOCK);
  36.         } else
  37.           *x=WINX1;
  38.  
  39.     /* any part of the line is below the window ? */
  40.     if (*y+*height-1 > WINY2)
  41.         /* yes */
  42.         *height=WINY2-*y+1;
  43.  
  44.     /* any part of the line on the right of the window ? */
  45.     if (*x+*length-1 > WINX2)
  46.         /* yes */
  47.         *length=WINX2-*x+1;
  48.  
  49.     return(OK);
  50. }
  51.  
  52.